#课堂练习
import random

num=1
sides=[1,2,3,4,5,6]

while num<=26:
    die_1=random.randint(1,7)
    print('[随机数]当前投掷：',num,' 次','，结果是：',die_1)
    die_2=random.choice(sides)
    print('[数  组]当前投掷：',num,' 次','，结果是：',die_2)
    num+=1

#将一个11面的骰子掷1000次
print('\n将一个11面的骰子掷1000次')

totals=[0,0,0,0,0,0,0,0,0,0,0,0,0]
for i in range(1000):
    dice_total=random.randint(2,12)
    tmp=totals[dice_total]
    #print('当前获取的随机数是：',dice_total,' totals[',dice_total,']=',tmp)
    totals[dice_total]+=1

for i in range(2,13):
    print('total',i,'came up',totals[i],' times')

#查找连续10次面朝上
from random import *
print('\n查找连续10次面朝上')
coin=['正面','反面']
heads_in_row=0
ten_heads_in_row=0
for i in range(100000):
    if choice(coin)=='正面':
        heads_in_row+=1
    else:
        heads_in_row=0
    
    if heads_in_row==10:
        ten_heads_in_row+=1
        heads_in_row=0

print('投掷硬币连续10正面的次数共有：%s次'%ten_heads_in_row)
    
#纸牌
class Card:
    def __init__(self,suit_id,rank_id):
        self.rank_id=rank_id
        self.suit_id=suit_id
        if self.suit_id==1:
            self.rank='Ace'
            self.value=1
        elif self.rank_id==11:
            self.rank='Jack'
            self.value=10
        elif self.rank_id==12:
            self.rank='Queen'
            self.value=10
        elif self.rank_id==13:
            self.rank='King'
            self.value=10
        elif 2<=self.rank_id<=10:
            self.rank=str(self.rank_id)
            self.value=self.rank_id
        else:
            self.rank='卡片错误'
            self.value=-1
        
        if self.suit_id==1:
            self.suit='方块'
        elif self.suit_id==2:
            self.suit='红桃'
        elif self.suit_id==3:
            self.suit='梅花'
        elif self.suit_id==4:
            self.suit='黑桃'
        else:
            self.suit='类型错误'
        self.short_name=self.rank[0]+self.suit[0]
        if self.rank=='10':
            self.short_name=self.rank+self.suit[0]
        self.long_name=self.rank+self.suit

#建立一副牌
import random

deck=[]
for suit_id in range(1,5):
    for rank_id in range(1,14):
        deck.append(Card(suit_id,rank_id))

#从一副牌中选5张牌作为一手牌
hand=[]
for cards in range(0,5):
    a=random.choice(deck)
    hand.append(a)
    deck.remove(a)

print()
for card in hand:
    print(card.short_name,'=',card.long_name,' Value:',card.value)
